#!/bin/sh
#
MARCIMPORT=/usr/local/marcimport
SABRE=/usr/local/vufind-smu
# Disable JETTY_CONSOLE output -- it causes problems when run by cron:
export JETTY_CONSOLE=/dev/null
#
date
#
############################################
# Get files...
cd $MARCIMPORT
pwd
cd full
# keep a back up of last times files
rm -r sussexincoming.old
cp -pr sussexincoming sussexincoming.old
#
cd sussexincoming
rm *
# sussexincoming is now empty.
scp talis@ustalis:/scratch/Aqua/initial/bib/prod_talis/norm/grabbed.bibsg*.mrc .
echo "Sussex file copy complete"
date
# check that we have some files and data
# ...
#
#################################################
# delete current index 
cd $SABRE
./vufind.sh stop
rm -rf solr/biblio/index.old
cp -pr solr/biblio/index solr/biblio/index.old

# ############################################ 
# Pre-process Sussex files
cd $MARCIMPORT/full/
rm -r sussexprocessed.old
cp -pr sussexprocessed sussexprocessed.old
for i in 1 2 3 4 5
do
  $SABRE/marc_merge_vufind.pl sussexincoming/grabbed.bibsg$i.mrc sussexprocessed/sussex$i.mrc susx
  echo Pre-processing Sussex file $i
done
date
#
# ##############################################
# vufind import sussex files
cd $SABRE
for i in 1 2 3 4 5
do
  echo ./import-marc.sh $MARCIMPORT/full/sussexprocessed/sussex$i.mrc
  echo Imported sussex$i.mrc
done
date
#
# pre-process Brighton files
#
#
# vufind import brighton files

################################################
# optimise and start it back up
cd $SABRE/util
echo starting optimise...
php optimize.php
cd $SABRE
./vufind start
echo "Full import finished"
date

